package com.github.pig.admin.controller.zhgl.notification;
import java.util.List;
import java.util.Map;
import java.util.Date;

import com.github.pig.admin.model.zhgl.notification.NotificationUser;
import com.github.pig.admin.service.sys.SysUserService;
import com.github.pig.admin.service.zhgl.notification.NotificationUserService;
import com.github.pig.admin.util.AjaxJson;
import com.github.pig.common.vo.UserVO;
import io.jsonwebtoken.Claims;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.github.pig.common.constant.CommonConstant;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.github.pig.common.util.Query;
import com.github.pig.common.util.R;
import com.github.pig.common.web.BaseController;

/**
 * <p>
 * 活动用户关联表 前端控制器
 * </p>
 *
 * @author xiaosa
 * @since 2018-07-17
 */
@RestController
@RequestMapping("/notificationUser")
public class NotificationUserController extends BaseController {
    @Autowired private NotificationUserService notificationUserService;
    @Autowired
    private SysUserService sysUserService;

    /**
    * 分页查询信息
    *
    * @param params 分页对象
    * @return 分页对象
    */
    @RequestMapping("/page")
    public Page page(@RequestParam Map<String, Object> params,NotificationUser notificationUser) {
        Page<NotificationUser> page = new Page<NotificationUser>(Integer.parseInt(params.getOrDefault("page", 1).toString())
                , Integer.parseInt(params.getOrDefault("limit", 10).toString()));
        // 获取到当前登录用户
        Claims claims = getCurrentUserInfo();
        String currentUserName =  (String) claims.get("user_name");
        UserVO userVO = sysUserService.findUserByUsername(currentUserName);
        if(!CommonConstant.MANAGE_NAME.equalsIgnoreCase(currentUserName)){
            // 获取到当前登录用户id
            Integer userId = userVO.getUserId();
            notificationUser.setUserId(userId+"");
        }
        return notificationUserService.getNotificationUserList(page,notificationUser);
    }

}
